package main.controller;

import com.jfoenix.controls.JFXToggleButton;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import main.view.Main;
import java.io.IOException;

public class RootLogin {

    private String inputUsername;
    private String inputPassword;

    @FXML
    private Button login;

    @FXML
    private JFXToggleButton isRoot;

    @FXML
    private TextField username;

    @FXML
    private PasswordField password;

    @FXML
    private Text actiontarget;

    @FXML
    void inputPassword(KeyEvent event) {
        this.inputPassword = this.password.getText();
        System.out.println("密码"+this.inputPassword);
    }

    @FXML
    void inputUserName(KeyEvent event) {
        this.inputUsername = this.username.getText();
        System.out.println("学号"+this.inputUsername);
    }

    @FXML
    void judgeUserType(ActionEvent event) throws IOException {
        new Main().initLogin();
    }

    @FXML
    void rootLogin(ActionEvent event) throws IOException {
        if(this.inputUsername==null || this.inputPassword==null){
            actiontarget.setFill(Color.FIREBRICK);
            actiontarget.setText("请输入正确的账户和密码！");
        }else{
            actiontarget.setFill(Color.color(0,0,0));
            actiontarget.setText("login……");
            if(this.inputUsername.equals("root") && this.inputPassword.equals("root")){
                new Main().initAdminMenu();
            }else {
                actiontarget.setFill(Color.FIREBRICK);
                actiontarget.setText("请输入正确的账户和密码！");
            }
        }
    }
}
